package cn.zzuisa.bluebox.config;

import javax.validation.Validation;
import javax.validation.Validator;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ValidatorConfiguration {
	/**
	 * 查的是加这一段开启方法参数验证，但是不加貌似也可以，但是方法参数验证必须加@RequestParam注解
	 * @return
	 */
//	@Bean
//	public MethodValidationPostProcessor methodValidationPostProcessor() {
//        MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
//        postProcessor.setValidator(validator());
//        return postProcessor;
//	}

    @Bean
    public Validator validator(){
    	return Validation.byProvider( HibernateValidator.class )
                .configure()
                .addProperty( "hibernate.validator.fail_fast", "true" )
                .buildValidatorFactory().getValidator();
    }
}
